<?php defined('IN_NWIDC') or exit('Access Invalid!');?>

<div class="tabmenu">
  <?php include template('layout/submenu');?>
</div>



<form method="get" action="index.php" target="_self">
  <table class="search-form ncsc-default-table order">
    <input type="hidden" name="act" value="store_order" />
    <input type="hidden" name="op" value="index" />
    <?php if ($_GET['state_type']) { ?>
    <input type="hidden" name="state_type" value="<?php echo $_GET['state_type']; ?>" />
    <?php } ?>

      <thead>

      <th>
          导入时间
      </th>
      <th>
          导入类型
      </th>
      <th>
          导入编号
      </th>
      <th>
          导入数量
      </th>
      <th>
          操作
      </th>
      </thead>
      <?php
          $m = Model()->table('order');
        $list = $m
            ->field("count(*) as num,import_sn as sn")
            ->where([
                'import_sn' => ['neq',''],
                'store_id' => $_SESSION['store_id'],
             ])
            ->group('import_sn')->page(20)->select();
          foreach($list as $item){
        ?>
              <tr>
              <td>
                  <?php echo date("Y-m-d H:i:s",strtotime($item['sn'])) ?>
              </td>
                  <td>
                      <?php
                        $f = ml('simport_list')->find([
                            'uuid' => $item['sn']
                        ]);
                          if($f)
                              echo "整合导入";
                          else
                              echo "普通导入";
                      ?>
                  </td>
              <td>
                    <?php echo $item['sn'] ?>
              </td>
              <td>
                  <?php echo $item['num'] ?>
              </td>
              <td>
                  <?php
                    if($f
                        ){
                      ?>
                        <a href="javascript:;" class="superexport" data-sn="<?php echo $item['sn'] ?>">整合导出</a>
                  <?php
                    }else {
                        ?>
                        <a href="javascript:;" class="export" data-sn="<?php echo $item['sn'] ?>">导出</a>
                        <?php
                    }
                  ?>
                  <a href="javascript:;" target="_blank" style="display: none;">
                      下载
                  </a>
              </td>
              </tr>
      <?php
          }
      ?>
      <script>
          $('[data-sn].export').click(function(){
              var sn = $(this).attr('data-sn');
              var index = layer.load();
              var _this = $(this);
              $.post('/shop/?sin=SinSexcel&p=orderExportBySn&arr=' + sn,function(msg){
                  layer.close(index);
                  if(msg.errcode != 0){
                      layer.msg("导出失败！");
                      return;
                  }
                  var file = msg.errmsg.file;
                  _this.next().attr("href",file).show();
              },'json');
          });

          $('[data-sn].superexport').click(function(){
              var sn = $(this).attr('data-sn');
              var index = layer.load();
              var _this = $(this);
              $.post('/shop/?sin=SinSexcel&p=orderSuperExportBySn&arr=' + sn,function(msg){
                  layer.close(index);
                  if(msg.errcode != 0){
                      layer.msg("导出失败！");
                      return;
                  }
                  var file = msg.errmsg.file;
                  _this.next().attr("href",file).show();
              },'json');
          });
      </script>
      <tr>
          <td colspan="100">
              <div class="pagination" style="padding-top: 20px;">
                  <?php echo $m->showpage() ?>
              </div>
          </td>
      </tr>
  </table>
</form>
<script charset="utf-8" type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/i18n/zh-CN.js" ></script>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/themes/ui-lightness/jquery.ui.css"  />
<script type="text/javascript">
$(function(){
    $('#query_start_date').datepicker({dateFormat: 'yy-mm-dd'});
    $('#query_end_date').datepicker({dateFormat: 'yy-mm-dd'});
    $('.checkall_s').click(function(){
        var if_check = $(this).attr('checked');
        $('.checkitem').each(function(){
            if(!this.disabled)
            {
                $(this).attr('checked', if_check);
            }
        });
        $('.checkall_s').attr('checked', if_check);
    });
    $('#skip_off').click(function(){
        url = location.href.replace(/&skip_off=\d*/g,'');
        window.location.href = url + '&skip_off=' + ($('#skip_off').attr('checked') ? '1' : '0');
    });
});
</script> 
